package com.xb;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @program: register-jerry
 * @description: 可重入锁源码分析
 * @author: xu.bin
 * @create: 2020-11-08
 */
public class ReentrantLockDemo {
    static ReentrantLock reentrantLock=new ReentrantLock();
    static Integer count=0;
    public static void main(String []args){
        new Thread(){
            @Override
            public void run() {
                try{
                    reentrantLock.lock();
                    count++;
                    Thread.sleep(10000000);
                    reentrantLock.lock();
                    reentrantLock.unlock();
                    reentrantLock.unlock();
                }catch (Exception e){
                    e.printStackTrace();
                }

            }
        }.start();
        new  Thread(){
            @Override
            public void run() {
                try{
                    reentrantLock.lock();
                    count++;
                    reentrantLock.unlock();
                }catch (Exception e){
                    e.printStackTrace();
                };
            }
        }.start();
    }
}